package ngat.oss;

import ngat.message.OSS.*;

import java.io.*;

/** 
 * Action: Shuts down Launcher and associated threads urgently by making Launcher 
 * return from its run() method.
 * The TSConnectThread for this TransactionRequest will receive a confirmation of 
 * this since, though the Launcher shuts down all the TSConnect threads before closing 
 * itself down.
 */
public class KILL_SERVERImpl extends TransactionImpl implements Serializable {
    
    /** Specifies the delay before the Launcher should be given the kill signal.*/
    protected long delay;
    
    /** Create a KILL_SERVERImpl to handle the specified request.*/
    public KILL_SERVERImpl (KILL_SERVER request) {
	super(request);
	delay = request.getDelay();
    }
    
    /**
     * Tell the Launcher to shutdown now - this is done using asynchronous
     * handoff via the Launcher$Assassin thread.
     * @return A Long holding the time the request was invoked.
     */
    public TRANSACTION_DONE exec() {
	
	Oss.getInstance().stop(Oss.STOP_CODE, delay);
	
	KILL_SERVER_DONE done  = new KILL_SERVER_DONE(request.getId());
	done.setSuccessful(true);
	done.setRequestTime(System.currentTimeMillis());
	return done;
    }
   
}
